package KK.Camera
{
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class Camera
	{
		static public const UPDATE:int=1;
		static public const NORMAL:int=0;
		
		
		private var state:int;
		private var _viewRect:Rectangle;
		private var _mapRect:Rectangle;
		public function Camera(width:int,height:int)
		{
			_mapRect=new Rectangle();
			_viewRect=new Rectangle();
			_viewRect.width=width;
			_viewRect.height=height;
			init();
		}
		private function init():void{
			state=UPDATE;
		}
		
		
		/**
		 * 镜头位置  
		 * @param x
		 * @param y
		 * 
		 */
		public function CameraSite(x:int,y:int):void{
			_viewRect.x=x>_mapRect.width-_viewRect.width?_mapRect.width-_viewRect.width:x;
			_viewRect.y=y>_mapRect.height-_viewRect.height?_mapRect.height-_viewRect.height:y;
			state=UPDATE;
		}
		
		/**
		 * 设置x 
		 * @param value
		 * 
		 */
		public function set x(value:Number):void{
			_viewRect.x=value;
		}
		/**
		 * 获取 x
		 * @return 
		 * 
		 */
		public function get x():Number{
			return _viewRect.x;
		}
		
		/**
		 * 设置y 
		 * @param value
		 * 
		 */
		public function set y(value:Number):void{
			_viewRect.y=value;
		}
		/**
		 * 获取y 
		 * @return 
		 * 
		 */
		public function get y():Number{
			return _viewRect.y;
		}
		
		/**
		 * 镜头大小  
		 * @param width
		 * @param height
		 * 
		 */
		public function CameraSize(width:int,height:int):void{
			_viewRect.width=width;
			_viewRect.height=height;
			state=UPDATE;
		}
		
		/**
		 * 设置地图 大小  
		 * @param width
		 * @param height
		 * 
		 */
		public function MapSize(width:int,height:int):void{
			_mapRect.width=width;
			_mapRect.height=height;
			state=UPDATE;
		}
		/**
		 * 获取  显示区域 
		 * @return 
		 * 
		 */
		public function get ViewRect():Rectangle
		{
			state=NORMAL;
			return _viewRect;
		}
		
		/**
		 * 是否更新  
		 * @return 
		 * 
		 */
		public function isUpdate():Boolean{
			return state==UPDATE;
		}
		
	}
}